/*
 * Copyright (C) 2017 The MoonLake Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package com.minecraft.moonlake.legendaryweaponrel.weapons.armor;

import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

public class RubberShield extends WeaponAbstractArmorBase {

    public RubberShield() {
        super("rubbershield", "&b橡胶盾", Material.IRON_CHESTPLATE);
    }

    @Override
    public String[] getLore() {
        return new String[] {
                "&7当装备时完全无视弓箭的伤害",
                "&7但是受到其他的伤害将为原来的 &a1.5 &7倍"
        };
    }

    @Override
    protected void onDamage(EntityDamageByEntityEvent event, Player player, LivingEntity dmg) {
        // 处理玩家受伤
        if(dmg instanceof Arrow) {
            // 如果攻击者实体为弓箭则阻止伤害事件
            event.setCancelled(true);
            return;
        }
        // 否则其余伤害将为原来的1.5倍
        double finalDamage = event.getFinalDamage();
        double doubleDamage = finalDamage * 1.5 - finalDamage;

        if(player.getHealth() <= doubleDamage) player.setHealth(0d); // 生命小于伤害则直接杀死
        else player.setHealth(player.getHealth() - doubleDamage); // 否则当前生命减去伤害
    }
}
